package com.homewoek;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author:Ren2048
 * @Date:2021/8/27
 * @Description:com.homewoek
 * @Version:1.8.0_261
 */

//3,编写Java程序,创建学员类Student,并添加姓名、年龄、性别等字段,
// 创建3个ArrayList<T>对象,指定T为Student类,每个ArrayList<T>中添加一些学员对象再创建HashMap-K,V>对象,
// 以年级名称为键,指定为String类型,指定value类型为ArrayList<Student>,
// 值为存放学员的ArrayList<T>对象,然后从HashMap<K,v>对象中获取某个班级的学员信息并输出。
public class Test {
    public static void main(String[] args) {
        ArrayList<Student> al1 = new ArrayList<Student>();
        ArrayList<Student> al2 = new ArrayList<Student>();
        ArrayList<Student> al3 = new ArrayList<Student>();
        Student stu1 = new Student("张三","男",18);
        Student stu2 = new Student("李四","男",19);
        Student stu3 = new Student("王五","男",20);
        Student stu4 = new Student("六子","男",21);
        al1.add(stu1);
        al2.add(stu2);
        al3.add(stu3);
        al3.add(stu4);
        HashMap<String,ArrayList<Student>> hm = new HashMap<String,ArrayList<Student>>();
        hm.put("12",al1);
        hm.put("13",al2);
        hm.put("14",al3);
        for (String s:hm.keySet()){
            System.out.println("grade:" + s + ", name:" + hm.get(s).get(0).name+", gander:"
                    +hm.get(s).get(0).gander+", age:"+hm.get(s).get(0).age);
            if (s.equals("14"))
                System.out.println("grade:" + s + ", name:" + hm.get(s).get(1).name+", gander:"
                        +hm.get(s).get(1).gander+", age:"+hm.get(s).get(1).age);
        }
    }
}
